<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">
        <i class="el-icon-s-home"></i>
        首页
      </el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/limits/store/list' }">
        <i class="el-icon-monitor"></i>
        权限管理
      </el-breadcrumb-item>
      <!-- 当前 -->
      <el-breadcrumb-item>角色管理</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="content">
      <div style="padding:40px;">
        <el-button size="small" @click="goAdd">添加角色</el-button>
        <table>
          <th>角色名称</th>
          <th>角色权限</th>
          <th>操作</th>
          <tr v-for="item in data" :key="item.id">
            <td>{{ item.name }}</td>
            <td>{{ item.radio }}</td>
            <td>
              <el-button type="text" @click="del(item.id)">删除</el-button>
              <el-button type="text" @click="set(item)">修改</el-button>
            </td>
          </tr>
        </table>
        <!-- 遮罩层 -->
        <div class="zz" v-show="flag">
          <div class="set">
            <!-- 头部 -->
            <div class="setTop">
              <p>修改角色</p>
              <i class="el-icon-close" style="font-size: 20px;font-weight: bold;" @click="flag = false"></i>
            </div>
            <div style="padding:40px;">
              <el-form ref="form" :model="form" label-width="100px">
                <el-form-item label="角色名称:">
                  <el-input size="small" placeholder="请输入角色名称" v-model="form.name" style="width: 200px;"></el-input>
                </el-form-item>
                <el-form-item label="权限设置:">
                  <div class="radio">
                    <el-radio v-model="form.radio" @input="change" label="首页">首页</el-radio>
                    <el-radio v-model="form.radio" @input="change" label="商品管理">商品管理</el-radio>
                    <el-radio v-model="form.radio" @input="change" label="订单管理">订单管理</el-radio>
                    <el-radio v-model="form.radio" @input="change" label="财务管理">财务管理</el-radio>
                    <el-radio v-model="form.radio" @input="change" label="优惠管理">优惠管理</el-radio>
                    <el-radio v-model="form.radio" @input="change" label="会员管理">会员管理</el-radio>
                    <el-radio v-model="form.radio" @input="change" label="活动管理">活动管理</el-radio>
                    <el-radio v-model="form.radio" @input="change" label="积分商城">积分商城</el-radio>
                    <el-radio v-model="form.radio" @input="change" label="权限管理">权限管理</el-radio>
                    <el-radio v-model="form.radio" @input="change" label="评价管理">评价管理</el-radio>
                  </div>
                </el-form-item>
              </el-form>
              <div class="btnDiv1">
                <el-button type="primary" @click="save" size="small">保存</el-button>
                <el-button size="small" @click="qx">取消</el-button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getRoleBx, setRoleBx, DelRoleBx } from '../../utils/api'
export default {
  data() {
    return {
      flag: false,
      data: [],
      form: {
        id: 0,
        name: '',
        radio: '1',
      }
    }
  },
  created() {
    this.render()
  },
  methods: {
    render() {
      getRoleBx().then(res => {
        this.data = res.data.data
      })
    },
    goAdd() {
      this.$router.push('/limits/addrole')
    },
    set(i) {
      this.flag = true
      this.form.name = i.name
      this.form.radio = i.radio
      this.form.id = i.id
    },
    save() {
      setRoleBx(this.form).then(res => {
        if (res.status == 200) {
          this.flag = false
          this.render()
        }
      })
    },
    change() {
     
    },
    qx() {
      this.flag = false
    },
    del(i) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        DelRoleBx({ id: i }).then(res => {
          if (res.status) {
            this.render()
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    }
  }
}
</script>
<style scoped>
table {
  margin: 30px auto;
  border: 1px solid #777777;
  border-collapse: collapse;
  text-align: center;
  width: 70%;
  font-size: 14px;
}

.btnDiv1 {
  width: 200px;
  display: flex;
  justify-content: space-between;
  margin-left: 100px;
}

.radio {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  width: 200px;
}

tr {
  height: 50px;
}

td {
  width: 150px;
  border: 1px solid #777777;
}

th {
  height: 50px;
  line-height: 50px;
  font-weight: normal;
  background-color: #F6F6F6;
  border: 1px solid #777777;
}

.el-radio {
  height: 25px;
}

.setTop {
  padding: 18px 22px;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #a5a5a5;
}

.set {
  font-size: 14px;
  width: 50%;
  height: 500px;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  background: #ffffff;
  border-radius: 5px;

}

.zz {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.5);
}</style>